package com.atguigu.edu2021.mock.stage;

import com.atguigu.edu2021.mock.bean.OrderInfo;
import com.atguigu.edu2021.mock.config.EduConstant;
import com.atguigu.edu2021.mock.factory.UserSession;
import com.atguigu.edu2021.mock.service.OrderInfoService;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component("end")
public class EndStage implements Stage {



    @Autowired
    OrderInfoService orderInfoService;



    @Override
    public boolean handle() {

        expireOrder();
        return true;
    }



    private  void expireOrder(){

        OrderInfo orderInfo  = UserSession.getOrderInfo();

        if(orderInfo!=null&&orderInfo.getOrderStatus().equals(EduConstant.ORDER_STATUS_UNPAID)) {
            orderInfo.setOrderStatus(EduConstant.ORDER_STATUS_CANCEL);
            orderInfo.setUpdateTime(DateUtils.addMinutes(UserSession.getCurDateTime(), 15));
            orderInfoService.saveOrUpdate(orderInfo);
        }

    }



}
